//
//  gridview.h
//  OpenglPing
//
//  Created by 100TV protocal on 12-11-28.
//
//

#import <UIKit/UIKit.h>

typedef enum {
    UIGridViewCellEditingStyleNone,
    UIGridViewCellEditingStyleDelete,
    UIGridViewCellEditingStyleInsert
} UIGridViewCellEditingStyle;

//btn
@interface UIButton(par)
@property (nonatomic, retain) NSNumber *nParameter;
@end

//cell
@interface gridviewcell : UIControl
{
	NSString* m_reuseIdentifier;
	int index;
}
@property(nonatomic,assign) int index;
-(NSString*) reuseIdentifier;
-(id) initWithFrame:(CGRect)frame reuseIdentifier:(NSString*) identifier;
@end

//bookcell
@interface gridviewbookcell : UIControl
{
	NSString* m_reuseIdentifier;
	int index;
}
@property(nonatomic,assign) int index;
-(NSString*) reuseIdentifier;
-(id) initWithFrame:(CGRect)frame reuseIdentifier:(NSString*) identifier;
@end
@interface bookcell : gridviewbookcell
@end

//gridview
@protocol GridViewDelegate;
@protocol GridViewDataSource;

@interface gridview : UIScrollView
{
    id<GridViewDataSource> dataSource;
    id<GridViewDelegate> delegate_grid;

    NSMutableDictionary* dequeArray;
    NSMutableDictionary* visibleCellDictionary;

    //boosstore
    NSMutableDictionary* dequeArrayBook;
    NSMutableDictionary* visibleCellDictionaryBook;
    BOOL isBookStore;

    UIView* footerView;
    UIView* headerView;
    BOOL loadData;
    UIActivityIndicatorView*  _activityView;
    NSMutableArray *cellFrameArray;
    BOOL getRidOfAnimation;
    CGFloat revertFrameH;
    CGFloat headerHeight;
    NSInteger left_width;

    CGFloat oldCellWidth;

    CGSize gridItemSize;
    
struct {
    unsigned int gridNumOfItems:1;
    unsigned int gridNumOfCol:1;
    unsigned int gridNumOfRow:1;
    unsigned int gridContentHeight:1;
    unsigned int gridContentWidth:1;
    unsigned int gridHspacer:1;
    
    unsigned	delegateWillDisplayCell:1;
    unsigned	delegateWillSelectItem:1;
    unsigned    delegateWillSelectItemMultiTouch:1;
    unsigned	delegateWillDeselectItem:1;
    unsigned	delegateDidSelectItem:1;
    unsigned    delegateDidSelectItemMultiTouch:1;
    unsigned	delegateDidDeselectItem:1;
    unsigned	delegateGestureRecognizerActivated:1;
    unsigned	delegateAdjustGridCellFrame:1;
    unsigned    delegateDidEndUpdateAnimation:1;
    
    unsigned int isEditing:1;
    unsigned int isAnimation:1;
    //bookstore
    unsigned int isBgBookStore:1;
    
} _gridFlags;

NSUInteger _selectedIndex;
UIButton * _systemEdit_Select;
UIButton * _systemEdit_Delete;
}
@property (nonatomic, assign) CGFloat headerHeight;
@property (nonatomic, retain) UIView * footerView;
@property (nonatomic, retain) UIView * headerView;
@property(nonatomic,assign) IBOutlet id<GridViewDataSource> dataSource;
@property(nonatomic,assign) IBOutlet id<GridViewDelegate> delegate_grid;

- (gridviewcell *) dequeueReusableCellWithIdentifier:(NSString *)identifier;
//book
- (gridviewbookcell*)dequeueReusableBookCellWithIdentifier:(NSString*)identifiler;

@property(nonatomic,assign) BOOL isBookStore;
/*
 reloadfooter
 */
-(void) reloadFooter;

/*
 重新加载数据
 */
-(void) reloadData;

/*
 获得单个cell
 */
-(gridviewcell *) getCellAtIndex:(int)index;

/*
 重新加载某一单元格
 */
-(void) reloadCellAtIndex:(int) index;

// Editing

@property(nonatomic,getter=isEditing) BOOL editing;    // default is NO. setting is not animated.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

@property(nonatomic,assign)NSInteger left_width;

@property(nonatomic,assign)CGFloat   delete_button_offsetX;//guojin add 2012-10-16删除按钮居中

@end

//protocal
@protocol GridViewDelegate <UIScrollViewDelegate>
@optional//可选
-(void) gridView:(gridview*) agridView willSelectCell:(gridviewcell*) acell atIndex:(unsigned int) aindex;
-(void) gridView:(gridview*) agridView didSelectCell:(gridviewcell*) acell atIndex:(unsigned int) aindex;
-(void) gridView:(gridview*) agridView willDisplayCell:(gridviewcell*) acell atIndex:(unsigned int) aindex;
-(void) gridView:(gridview*) agridView didSelectCellUp:(gridviewcell*) acell atIndex:(unsigned int) aindex;
-(void) gridView:(gridview*) agridView didSelectCellOutSizeUp:(gridviewcell*) acell atIndex:(unsigned int) aindex;
//loading data
-(BOOL) gridview:(gridview*) agridView didHeader:(BOOL)isheader;
//edit
- (void)gridView:(gridview*) agridView commitEditingStyle:(UIGridViewCellEditingStyle)editingStyle atIndex:(unsigned int)aindex;
@end

@protocol GridViewDataSource <NSObject>
@required
-(unsigned int) numOfGridViewItem:(gridview*) agridView;
-(CGSize) sizeOfGridViewItem:(gridview*) agridView;
-(gridviewcell*) gridView:(gridview*) agridView cellForIndex:(unsigned int) aindex;
@optional
-(float) heightOfGridViewFooter:(gridview*) agridView;
-(UIView*) footerOfGridView:(gridview*) agridView;
-(void) cellWillDisAppear:(gridviewcell *)agridItem;
@end







